<style>
	.layui-form-label { width: 30%!important;}
	.layui-form-label div{ font-size: 12px;font-weight: normal;color: #AC6363;}
	.layui-input-block {margin-left: 30%;}
	.layui-form-item{border-bottom: 1px solid #f5f5f5;}
	.layui-card-body, .layui-card-header, .layui-form-label, .layui-form-mid, .layui-form-select, .layui-input-block, .layui-input-inline, .layui-textarea { width: 700px; }
	.regular .layui-form-select{float: left; width: 150px;}
</style>
<link rel="stylesheet"href="__ADMIN__/editor/css/editormd.css" />

	<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
		
			<!-- END RIBBON -->
			<div class="content">
				<div class="panel panel-default panel-intro">
					<div class="panel-heading">
						<div class="panel-lead">
							<em>CMS - 【{$title}】- 修改内容</em>
							...
						</div>
					</div>
					<div class="panel-body">
						<div class="tab-content">
							<div class="tab-pane fade active in">
								<div class="widget-body no-padding">
									<div class="bootstrap-table">
										
										<div class="fixed-table-toolbar">
											<div class="bs-bars pull-left">
												<div class="toolbar">
													<a href="javascript:window.location.reload();" class="btn btn-primary btn-refresh" title="刷新">
														<i class="fa fa-refresh"></i>
													</a>
												</div>
											</div>
											<div class="columns columns-right btn-group pull-right">
												
											</div>
										</div>
										<div class="fixed-table-container" style="padding-bottom: 0px;">
	
	
	<div class="fixed-table-body">
	<div role="main">
		<div class="tab-content tab-addtabs">
			<div>
				<div class="row">
					<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
							<div class="content">
							<form class="layui-form" >
									
								{foreach name="field" item="v"}
								{php} $list = [];{/php}
								{if condition="$v['if_type'] == 'select' || $v['if_type'] == 'radio' || $v['if_type'] == 'checkbox'"}
									{php}
										$str = str_replace('，', ',', $v['if_content']);
										$array = explode(',', $str);
										foreach ($array as $val) {
											$arr = explode('|', $val);
											$list[$arr[0]] = $arr[1];
										}
									{/php}
								{/if}
								<div class="layui-form-item">
									<label class="layui-form-label" style="padding-bottom:0">
										{$v.if_title}
										<div>{$v.if_des}</div>
									</label>
									<div class="layui-input-block">
										{if condition="$v['if_type'] == 'text' || $v['if_type'] == 'int'"}
											<input type="text" class="layui-input" id="{$v.if_name}" value="{php} echo $info[$v['if_name']];{/php}">
										{elseif condition="$v['if_type'] == 'textarea'"/}
											<textarea style="min-height: 60px;margin-bottom: 10px;" class="layui-textarea" id="{$v.if_name}">{php} echo $info[$v['if_name']];{/php}</textarea>
										{elseif condition="$v['if_type'] == 'select'"/}
											<select class="layui-input" id="{$v.if_name}">
												<option value="">请选择{$v.if_title}</option>
												{foreach name="list" item="vo" key="k"}
													<option value="{$k}" {eq name="k" value="$info[$v['if_name']]"}selected{/eq}>{$vo}</option>
												{/foreach}
											</select>
										{elseif condition="$v['if_type'] == 'radio'"/}
											{foreach name="list" item="vo" key="k"}
												<input type="radio" name="{$v.if_name}" value="{$k}" title="{$vo}" {eq name="k" value="$info[$v['if_name']]"}checked{/eq}>
											{/foreach}
										{elseif condition="$v['if_type'] == 'checkbox'"/}
											{php}
												$str = str_replace('，', ',', $info[$v['if_name']]);
												$default = explode(',', $str);
											{/php}
											{foreach name="list" item="vo" key="k"}
												<input type="checkbox" lay-skin="primary" name="{$v.if_name}" value="{$k}" title="{$vo}" {if condition="in_array($k, $default)"}checked{/if}>
											{/foreach}
										{elseif condition="$v['if_type'] == 'editor'"/}
											{if condition="$v['if_text'] == 1"}
												<div id="{$v.if_name}">{php} echo $info[$v['if_name']];{/php}</div>
											{elseif condition="$v['if_text'] == 2"/}
												<div id="{$v.if_name}" style="z-index:99999">
													<textarea name="my-editormd-markdown-doc" style="display:none;">{php} echo $info[$v['if_name']];{/php}</textarea>
													<!-- 注意：name属性的值-->
													<textarea name="my-editormd-html-code" style="display:none;"></textarea>
												</div>
											{elseif condition="$v['if_text'] == 3"/}
												<textarea class="layui-textarea" id="{$v.if_name}">{php} echo $info[$v['if_name']];{/php}</textarea>
											{/if}
										{elseif condition="$v['if_type'] == 'enclosure'"/}
											<button type="button" class="layui-btn layui-btn-sm layui-btn-normal" id="{$v.if_name}">
												<i class="layui-icon">&#xe67c;</i>上传附件
											</button>
											<span id="{$v.if_name}_url">{php} echo $info[$v['if_name']];{/php}</span>
										{elseif condition="$v['if_type'] == 'image'"/}
											<button type="button" class="layui-btn layui-btn-sm layui-btn-normal" id="{$v.if_name}">
												<i class="layui-icon">&#xe67c;</i>上传图片
											</button>
											<img id="{$v.if_name}_url" src="{php} echo $info[$v['if_name']];{/php}" width="50">
										{elseif condition="$v['if_type'] == 'images'"/}
											<button type="button" class="layui-btn layui-btn-sm layui-btn-normal" id="{$v.if_name}">
												<i class="layui-icon">&#xe67c;</i>多图片上传
											</button>
											<div id="{$v.if_name}_url">
												{php}$img_list = explode(',', $info[$v['if_name']]);{/php}
												{foreach name="img_list" item="val"}
													<img class="delete_img" src="{$val}" width="100">
												{/foreach}
											</div>
										{/if}
										
									</div>
								</div>

								{/foreach}
								
								<div class="layui-form-item">
									<div class="layui-input-block">
										<button type="button" class="layui-btn layui-btn-sm layui-btn-normal push_server">立即修改</button>
										<button type="reset" class="layui-btn layui-btn-sm layui-btn-primary">重置</button>
									</div>
								</div>
	
							</form>
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>
	
	
	
	
											</div>
										</div>
									</div>
								</div>
							</div>
						</div>
					</div>
				</div>
			</div>
		</div>
	
	
	
	
<script type="text/javascript" src="__ADMIN__/js/wangEditor.min.js"></script>
<script type="text/javascript" src="__ADMIN__//editor/editormd.min.js"></script>										
<script>
{foreach name="field" item="v"}
var {$v.if_name};					
{/foreach}

layui.use(['form', 'layedit', 'upload'], function(){
	var form = layui.form, upload = layui.upload, layedit = layui.layedit;
	// 设置特殊JS
	{foreach name="field" item="v"}
		{if condition="$v['if_type'] == 'editor'"/}
			{if condition="$v['if_text'] == 1"}
				// wangEditor编辑器
				var E = window.wangEditor
				var editor = new E('#{$v.if_name}')
				editor.customConfig.uploadImgServer = '{:url("common/wangEditor")}'
				editor.customConfig.uploadFileName = "file";
				editor.create()
			{elseif condition="$v['if_text'] == 2"/}
				//editor编辑器
				editormd("{$v.if_name}", {
					width   : "100%",
					height  : 340,
					syncScrolling : "single",
					path    : "__ADMIN__/editor/lib/",//注意2：你的路径
					saveHTMLToTextarea : true,//注意3：这个配置，方便post提交表单
					/**上传图片相关配置如下*/
					imageUpload : true,
					imageFormats : ["jpg", "jpeg", "gif", "png", "bmp", "webp"],
					imageUploadURL : "{:url('common/editor')}",//注意你后端的上传图片服务地址
					emoji: true,//emoji表情，默认关闭
					flowChart: true,//开启流程图支持，默认关闭
					sequenceDiagram: true,//开启时序/序列图支持，默认关闭,
					/**设置主题颜色*/
					editorTheme: "pastel-on-dark",
					theme: "gray",
					previewTheme: "dark"
				});
			{elseif condition="$v['if_text'] == 3"/}
				// Layui编辑器
				layedit.set({
					uploadImage: {
						url: '{:url("common/add_images")}'
					}
				});
				{$v.if_name} = layedit.build('{$v.if_name}');
			{/if}
		{elseif condition="$v['if_type'] == 'enclosure'"/}
			//执行实例
			upload.render({
				elem: '#{$v.if_name}' //绑定元素
				,url: '{:url("common/add_images")}' //上传接口
				,accept: 'file'
				,done: function(res){
				//上传完毕回调
					$('#{$v.if_name}_url').html(res.data.src);
					$.thinkmimi({Content : res.msg, Type:1, Align:'right', OutTime:2000});
				}
				,error: function(){
					$.thinkmimi({Content : '上传失败！', Type:2, Align:'right', OutTime:2000});
				}
			});
		{elseif condition="$v['if_type'] == 'image'"/}
			//执行实例
			upload.render({
				elem: '#{$v.if_name}' //绑定元素
				,url: '{:url("common/add_images")}' //上传接口
				,accept: 'images'
				,done: function(res){
				//上传完毕回调
					$('#{$v.if_name}_url').attr('src',res.data.src);
					$.thinkmimi({Content : res.msg, Type:1, Align:'right', OutTime:2000});
				}
				,error: function(){
					$.thinkmimi({Content : '上传失败！', Type:2, Align:'right', OutTime:2000});
				}
			});
		{elseif condition="$v['if_type'] == 'images'"/}
			//执行实例
			upload.render({
				elem: '#{$v.if_name}' //绑定元素
				,url: '{:url("common/add_images")}' //上传接口
				,accept: 'images'
				,multiple:true
				,done: function(res){
				//上传完毕回调
					$('#{$v.if_name}_url').append('<img class="delete_img" src="'+res.data.src+'" width="100">');
					$.thinkmimi({Content : res.msg, Type:1, Align:'right', OutTime:2000});
				}
				,error: function(){
					$.thinkmimi({Content : '上传失败！', Type:2, Align:'right', OutTime:2000});
				}
			});
		{/if}
	{/foreach}
});

// 点击删除已经上传的图片
$(".layui-input-block").on("dblclick",".delete_img",function(){
	var url = $(this).attr('src');
	var _this = $(this);
	$.ajax({
		type: 'post',
		data: {'url':url},
		async: false,
		url: "{:url('common/delete_img')}",
		success: function(data) {
			if (data.code == '01') {
				$.thinkmimi({Content : data.msg, Type:2, Align:'right', OutTime:2000});
			} else {
				$.thinkmimi({Content : data.msg, Type:1, Align:'right', OutTime:2000,});
				$(_this).remove();
			}
		}
	});
})
	
$('.push_server').click(function(){
	var layedit = layui.layedit;
	var jsonObj= {
		'id':'{$info.id}',
		'pid':'{$pid}',
		'im_id':'{$im_id}',
	};
	{foreach name="field" item="v"}
		{if condition="$v['if_type'] == 'text' || $v['if_type'] == 'int' || $v['if_type'] == 'textarea' || $v['if_type'] == 'select'"}
			jsonObj.{$v.if_name} = $('#{$v.if_name}').val();
		{elseif condition="$v['if_type'] == 'radio'"/}
			var i = $('input[name="{$v.if_name}"]:checked').val();
			if (typeof(i) == "undefined"){ 
				jsonObj.{$v.if_name} = '';
			} else {
				jsonObj.{$v.if_name} = i;
			}
		{elseif condition="$v['if_type'] == 'checkbox'"/}
			var i = '';
			$("input:checkbox[name='{$v.if_name}']:checked").each(function(){
				i += $(this).val()+',';
			});
			jsonObj.{$v.if_name} = i.replace(/(^,*)|(,*$)/g, "");
		{elseif condition="$v['if_type'] == 'editor'"/}
			{if condition="$v['if_text'] == 1"}
				jsonObj.{$v.if_name} = $('#{$v.if_name} .w-e-text').html();
			{elseif condition="$v['if_text'] == 2"/}
				jsonObj.{$v.if_name} = $('#{$v.if_name} textarea').val();
			{elseif condition="$v['if_text'] == 3"/}
				jsonObj.{$v.if_name} = layedit.getContent({$v.if_name});
			{/if}
		{elseif condition="$v['if_type'] == 'enclosure'"/}
			jsonObj.{$v.if_name} = $('#{$v.if_name}_url').html();
		{elseif condition="$v['if_type'] == 'image'"/}
			jsonObj.{$v.if_name} = $('#{$v.if_name}_url').attr('src');
		{elseif condition="$v['if_type'] == 'images'"/}
			var i = '';
			$('#{$v.if_name}_url').find('img').each(function() {
                i += $(this).attr('src')+',';
			});
			jsonObj.{$v.if_name} = i.replace(/(^,*)|(,*$)/g, "");
		{/if}
		{/foreach}

		$.ajax({
			type: 'post',
			data: jsonObj,
			async: false,
			url: "{:url('upd')}",
			success: function(data) {
				var array = eval('('+data+')');
				if (array['code'] == '01') {
					$.thinkmimi({Content : array['msg'], Type:2, Align:'right', OutTime:2000});
				} else {
					$.thinkmimi({Content : array['msg'], Type:1, Align:'right', OutTime:2000,});
					window.setTimeout(function(){
						window.location.href = '{:url("index", ["pid"=>$pid])}';
					}, 700);
				}
			}
		});
	
	});
	
	</script>